﻿using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class ObjLinkFmla: ObjItem
    {
        private ObjFmla fmla;

        protected override FtType Ft{get{ return FtType.Sft;}}

        protected override void ReadContent(BinaryReader reader)
        {
            fmla = new ObjFmla();
            fmla.Read(reader, false);
        }

        protected override void WriteContent(BinaryWriter writer)
        {
            fmla.Write(writer);
        }
    }
    enum FtType: ushort
    {
        FtPictFmla = 0x0009,
        Sft = 0x14,
    }
    abstract class ObjItem
    {
        public void Read (BinaryReader reader)
        {
            var ft = (FtType)reader.ReadUInt16();
            Contract.Assert(ft == this.Ft);
            ReadContent(reader);
        }
        public void Write (BinaryWriter writer)
        {
            writer.Write((ushort)Ft);
            WriteContent(writer);
        }

        protected abstract void WriteContent(BinaryWriter writer);

        protected abstract void ReadContent(BinaryReader reader);

        protected abstract FtType Ft { get; }
    }
}